Repository navigation
child_process: reject invalid environment variable names - #67659
ShogunPanda wants to merge 1 commit into
Conversation
Keys in the `env` option that are empty or that contain `=` cannot be represented in the `KEY=VALUE` form used by the child process environment. They were passed through unchanged, so the child received a different variable than the one the caller wrote. Throw `ERR_INVALID_ARG_VALUE` for them, as is already done for keys that contain null bytes. On Windows, a leading `=` is allowed, as it is used by per-drive variables such as `=C:`. Signed-off-by: Paolo Insogna <paolo@cowtech.it>
| invalidKeys.push('=C:'); | ||
| } else { | ||
| // A lone '=' is not a valid name on Windows either. | ||
| invalidKeys.push('='); |
There was a problem hiding this comment.
I think it might be worth testing the lone = unconditionally, not just for Windows.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #67659 +/- ##
==========================================
+ Coverage 90.72% 90.73% +0.01%
==========================================
Files 801 801
Lines 280960 280967 +7
Branches 54260 54270 +10
==========================================
+ Hits 254892 254932 +40
+ Misses 16248 16199 -49
- Partials 9820 9836 +16
🚀 New features to boost your workflow:
|
|
On Windows, in addition to the lone For comparison: Edit: |
child_process.spawn()and friends build the child environment asKEY=VALUEstrings. A key inoptions.envthat is empty or thatcontains
=cannot be represented that way: for example{ 'A=B': 'C' }producedA=B=C, which the child reads as variableAwith value
B=C.This throws
ERR_INVALID_ARG_VALUEfor such keys innormalizeSpawnArguments(), next to the existing null byte check. OnWindows a leading
=is still accepted, becauseprocess.envcontainsper-drive entries like
=C:andenv: process.envmust keep working.On POSIX,
process.envdoes not expose entries starting with=, soenv: process.envis unaffected.This is a bug fix and not an API change: such input has never been
representable, and the child always received a different variable than
the one requested. The same applies to the null byte validation of
env, which landed without a semver label and was backported tov18.x and v19.x (#44782).
Includes a test covering
spawn,spawnSync,exec,execSync,execFile,execFileSyncandfork, a positive case for a leading=on Windows, and a one line doc note.